using System;
using UnityEngine;

namespace Framework
{
    public class WaitAction<T> : Behavior<T>
    {
        private float _waitTime;
        private float _startTime;

        public WaitAction(float waitTime)
        {
            _waitTime = waitTime;
        }

        public override void OnStart(T context)
        {
            base.OnStart(context);
            _startTime = 0f;
        }

        public override TaskStatus Update(T context)
        {
            if (_startTime == 0f)
            {
                _startTime = Time.timeSinceLevelLoad;
            }

            if (Time.timeSinceLevelLoad - _startTime >= _waitTime)
            {
                return TaskStatus.Success;
            }

            return TaskStatus.Running;
        }
    }
}